//var json = [{ name : "Trumpeter Finch" },{ name : "Magnificent Frigatebird" },{ name : "Bufflehead" },{ name : "Snowfinch" },{ name : "Pallid Swift" },{ name : "House Finch" }];

$(document).ready(function(){
	Initialize();
        SetFocus();

	$("#keyword").autocomplete( edp_domain_url + "ajax_search_suggestion/?tiny=1",
//	$("#keyword").autocomplete( json,
	{
		minChars: 0,
		max: 8,
		width: $("#keyword").width(),
//		matchContains: "word",
		autoFill: false
//		formatItem: function(row, i, max) {
//			return row.name;
//		},
//		formatMatch: function(row, i, max) {
//			return row.name;
//		},
//		formatResult: function(row) {
//			return row.name;
//		}
	});
});

function CheckSearchAction(){
        if( $("#keyword").val() == "请输入要搜索的关键词" ){
                $("#keyword").val("");
        }
}

function SetFocus(){
        //      var str = $("#keyword").val();
        //when search input box set to focus, clear the field
        $("#keyword").focus(
                function(){
                        if( $("#keyword").val() == "请输入要搜索的关键词" ){
                                $("#keyword").val("");
                        }
                }
        )
        $("#keyword").blur(
                function(){
                        if( $("#keyword").val() == "" ){
                                $("#keyword").val("请输入要搜索的关键词");
                        }
                }
        )
}

function Initialize(){
        // add search type action
        $("#searchtype").change(
                function () {
                        var str = $("#searchtype option:selected").val();
                        //$("#page").val(str);
                        $( "#searchform" ).attr("action", str );
                });

        $( "#searchform" ).submit(
                function(){
                        CheckSearchAction();
                });

        var str = $('#keyword').val();
        if( "" == str ){
                $("#keyword").val("请输入要搜索的关键词");
        }
        else{
                $("#keyword").val( str );
        }
}
